home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Mac OS Development Toolkit / Automation Essentials 2.3.0 / Host Automation Folder / SPEC Libs / StandardFile.Lib < prev    next >
Encoding:
Text File  |  1998-03-19  |  38.0 KB  |  1,006 lines  |  [TEXT/MPS ]

  1. #
  2. # ****************************************************************************
  3. #
  4. #    File Name:    StandardFile.Lib
  5. #
  6. #    Contains:    Tasks that support Standard File operations.
  7. #
  8. #    Written by:    KTA, KL, ML, GS et al
  9. #
  10. #    Copyright:    © 1993-1996 by Apple Computer, Inc., all rights reserved.
  11. #
  12. # ****************************************************************************
  13. #            C h a n g e        H i s t o r y (most recent first):
  14. # ****************************************************************************
  15. #
  16. #        Vers      Date        Author        Description
  17. #        ----    --------    ------    ---------------------------------------------
  18. #    <1.1.18>      5/1/96    MDF        Revert() - handles button selection for Intl         case
  19. #                                    correctly.  OpenFile() - removed feature         for handling
  20. #                                    MacEasy Open in since no longer         applicable.
  21. #    1.1.17+>      5/1/96    MDF        Revert() - handles button selection for Intl case correctly.
  22. #                                    OpenFile() - removed feature for handling MacEasy Open in since
  23. #                                    no longer applicable.
  24. #    <1.1.17>    11/21/95    ML        SaveAs - revise for dirty quit.  Revert - add support for
  25. #                                    international
  26. #    1.1.16+>    11/20/95    ML        SaveAs - revise for dirty quit
  27. #    <1.1.16>     4/11/95    KTA        Syntax Error : Forgot ')'
  28. #    <1.1.15>     4/11/95    KTA        SaveAs(), OpenFile() - Insure global gIsSys7 is defined.
  29. #    <1.1.14>     2/28/95    KTA        SaveAs(), ReplaceExist() - Added calls to TruncateString().
  30. #    <1.1.13>     2/28/95    KTA        SaveAs(), ReplaceExist() - Handle filenames longer than 31
  31. #                                    characters
  32. #    <1.1.12>     2/14/95    KTA        SaveAs() - Call _MatchBoolean before trying to collect buttons
  33. #                                    on 'Replace Existing' Dialog to avoid calling the
  34. #                                    DefaultHandler.
  35. #    <1.1.11>     2/14/95    KTA        SaveAs(), OpenDoc() - Added BooleanFlag to FindWindow() call
  36. #    <1.1.10>     2/10/95    ML        IsStandardFile, CancelStandardFile - Use MatchBoolean instead of
  37. #                                    Match
  38. #     <1.1.9>     1/19/95    KTA        Changed the name of ExceptionHandler() to ExceptionDispatcher().
  39. #     <1.1.8>      1/9/95    KTA        SFNavigate(), SFType() - Fixed bug when StandardFile was already
  40. #                                    at the Desktop errors occured
  41. #     <1.1.7>    12/13/94    ML        Revise IsSys7 to gIsSys7, change IsSys7 to gIsSys7
  42. #     <1.1.6>     12/1/94    ML        Revise Revert()
  43. #     <1.1.5>    11/30/94    ML        Added exception handling support
  44. #     <1.1.4>     7/18/94    KTA        SFNavigate() - Added a check to insure that PathList is defined.
  45. #     <1.1.3>      5/9/94    KTA        SaveAs() - If not IsStandardFile() wait and try to match again.
  46. #     <1.1.2>      5/3/94    ML        Revise Easy open dialog check
  47. #     <1.1.1>      5/2/94    ML        Better check for Mac Easy Open Dialog
  48. #     <1.1.0>     4/28/94    KTA        SaveAs() - If unable to match 'Replace Existing dialog' try again.
  49. #    1.0.211>     4/20/94    ML        Add Mac Easy Open Dialog Check to OpenFile
  50. #    1.0.210>     4/20/94    ML        marked tasks
  51. #    <1.0.29>      4/7/94    ML        Add global gReplaceExistHook1 and gReplaceExistHook2
  52. #     <1.0.28>    1/7/94        RTV        OpenFile was passing a list to TCSEnd instead of a string for the doc name
  53. #     <1.0.27>    12/16/93    KTA        ModifyDocument was not returning correct values.
  54. #     <1.0.26>    12/14/93    KTA        Changed the way ModifyDocuemtn handles return values.
  55. #     <1.0.25>    12/13/93    KTA        OpenFile returns the name of the file it opened.
  56. #     <1.0.24>    11/19/93    NAGA    modify TCS format
  57. #     <1.0.23>     10/05/93    KTA        Revert() - Added longer wait before trying to dismiss dialog and 
  58. #                                    support for hierachical menus
  59. #     <1.0.22>     10/05/93    KTA        ModifyDocument() - Change returnVal to a 1 if it was successful.
  60. #     <1.0.21>     9/30/93    KTA        SaveAs() - Updated the output after saving a document.
  61. #     <1.0.20>     9/28/93    KTA        ModifyDocument() - Added TCS - 'Modify a Document'
  62. #     <1.0.19>     9/28/93    KTA        ModifyDocument() - Handle problem caused if gModifyDocument hook doesn't return a value
  63. #     <1.0.18>     9/22/93    KTA        Renamed gSaveOtherFormat -> SaveAsHook1,  gEndTimer -> SaveAsHook2
  64. #                                    gDismissSFPut -> gSaveAsHook3,gOpenFileHook -> gOpenFileHook1, 
  65. #                                    gEndTimer ->gOpenFileHook2, Removed pParameter1 from OpenFile()
  66. #     <1.0.17>     9/14/93    KTA        SaveAs() - gCustomRetrievedDoc wasn't being used 
  67. #                                    because it was not defined as global.
  68. #     <1.0.16>     9/9/93        KTA        Removed all slang phrases from output.
  69. #     <1.0.15>     8/30/93    KTA        Updated task headers and parameters.
  70. #     <1.0.14>     8/25/93    KTA        Added support for parity checking the TCS stack.
  71. #     <1.0.13>     7/30/93    KTA        IsStandardFile - return window descriptor, ModifyDocument return
  72. #                                    success/Failure. Openfile better check if standardfile gone.
  73. #     <1.0.12>     7/23/93    KTA        SaveAs() - moved gDismissSFPut to before we verify filename.
  74. #     <1.0.11>     7/22/93    KTA        Fixed bugs with file name verificaton, SaveAS(), OpenFile().
  75. #     <1.0.10>     7/19/93    KTA        FindWindow() now supports descriptors - updated references.
  76. #     <1.0.9>     7/15/93    KTA        Added undefined task reference - gReplaceExisting.  Hook to
  77. #                                    handle a custom "replace existing?" dialog. This was done for Lotus 123.
  78. #     <1.0.8>     7/14/93    KTA        International Support: See SaveAs(), OpenFile(),
  79. #                                    CancelStandardFile(), Revert(), and Save().
  80. #     <1.0.7>      7/6/93    KTA        CustomRetrieveDoc change had a syntax error
  81. #     <1.0.6>      7/6/93    KTA        Performance Support
  82. #        <1+>     5/21/93    NAGA    Adding header and porting old files to follow new standards
  83. #
  84. # ****************************************************************************
  85. #
  86.  
  87. ########################################################################
  88. #                            External libraries 
  89. #=======================================================================
  90. Libraries "String.Lib","TCS.Lib","Output.Lib","UserInterface.Lib",
  91. "ExceptionHandling.lib", "TargetCheck.Lib";
  92.  
  93. #########################################################################
  94. #            SaveAs(pNameDoc, pReplaceFlag, pSelectSaveAs, pPathlist)
  95. #========================================================================
  96. # Author:        KTA
  97. # Description:    This routine will type a name (pNameDoc) into the text edit
  98. #                field.  Then it will press the ReturnKey to save the file.
  99. #                If there is a document already named <pNameDoc> a dialog will
  100. #                appear. If the <pReplaceFlag> evaluates to false
  101. #                it will select NO to 'Replace Existing?' dialog. It will
  102. #                then type the time (based on a 24 hour clock) after the
  103. #                name and retype the ReturnKey. The Default is to replace
  104. #                an existing document with the same name. It will also call
  105. #                getNewFileName to create a file name if one is not provided.
  106. # Parameters:    pNameDoc - string holding the name to name the document
  107. #                pReplaceFlag - 0 to select 'No' to 'Replace Existing' dialog
  108. #                              1 to select 'Yes' to replace exisiting file.
  109. #                pSelectSaveAs - Flag which indicates whether or not to select
  110. #                                SaveAs menuItem. 
  111. #                                0 - Do not select SaveAs MenuItem
  112. #                                1 - Select the SaveAs menuItem
  113. #                                {List} - Select the SaveAs menuItem using the 
  114. #                                        ord specified. e.g. {5,2}
  115. #                pPathlist - Path to navigate before saving - should be complete path.
  116. # Returns:        0 - Unable to dismiss SFPut or never present to begin with
  117. #                1 - Dismissed SFPut ok, saved file, ReplaceExist not called
  118. #                2 - Dismissed SFPut ok, saved file, ReplaceExist called
  119. # Examples:        SaveAs('Untitled1'); to name the file 'Untitled1'
  120. # Assumptions:    That the SF_Put dialog is present
  121. #     
  122. #========================================================================
  123. # History:
  124. # KTA    7/06/93        Performance Support: EndTimer
  125. # KTA    7/07/93        Ability to pass in saveAs menu, if pSelectSaveAs is list of menuItems
  126. # KTA    7/13/93        Added undefined task reference gReplaceExisitng
  127. # KTA    7/19/93        Changed call to FindWindow() to pass a descriptor.
  128. # KTA    7/22/93        if can't match (gActualFileName) reassign to string we typed
  129. # KTA    8/24/93        TCS stack parity check
  130. # KTA    9/14/93        gCustomRetrievedDoc wasn't being used because it was not
  131. #                    defined as global
  132. # KTA    9/22/93        Changed gSaveOtherFormat to gSaveAsHook1
  133. #                     Changed gEndTimer to gSaveAsHook2
  134. #                     Changed gDismissSFPut to gSaveAsHook3
  135. # KTA    9/30/93        Updated the output after saving a document.
  136. # KTA    4/28/94        If couldn't match 'Replace Existing' Try again (slow Machine)
  137. # KTA    5/09/94        If not IsStandardFile() try to match again
  138. # ML     11/29/94    Added exception handling support
  139. # ML     12/13/94    revised IsSys7 to gIsSys7
  140. # KTA    2/14/95        Added BooleanFlag to FindWindow() call
  141. # KTA    2/14/95        Call _MatchBoolean before trying to collect buttons on
  142. #                    'Replace Existing' Dialog to avoid calling the DefaultHandler.
  143. # KTA    2/28/95        Handle filenames longer than 31 characters
  144. # KTA    2/28/95        Added call to TruncateString().
  145. #    ML    11/20/95    revise for dirty quit - add pCheckSaveDocWindow
  146. #########################################################################
  147. TASK SaveAs(pNameDoc := "", pReplaceFlag := true, pSelectSaveAs := False, 
  148.             pPathlist := global gSFPUTLocation, pCheckSaveDocWindow := 1) 
  149. begin
  150.     global gIsSys7, gLastSavedFile, gActualFileName;
  151.     returnVal := 0;
  152.     
  153.     if(isUndefined(global gIsSys7))
  154.         isSystem7();
  155.     
  156.     if (pSelectSaveAs)
  157.     begin
  158.         TCSStart({ 1, global kTCSetSFSave },"SaveAs");                        # Start TCS
  159.         if(typeOf(pSelectSaveAs) = 'list')
  160.             thisReturn := selectmenuItem(pSelectSaveAs[1],pSelectSaveAs[2]);
  161.         else
  162.             thisReturn := selectmenuItem("Save As", "File");
  163.         TCSEnd({ 1, global kTCSetSFSave },thisReturn);        # Select the MenuItem
  164.     end;
  165.  
  166.     wait(2);
  167.     ## Check to see if Standard File is present
  168.     isPresent := IsStandardFile();
  169.     if not(isPresent)
  170.     begin
  171.         wait(8);
  172.         isPresent := IsStandardFile();
  173.     end;
  174.  
  175.     ## Continue only if Standard File is present
  176.     if (isPresent) 
  177.     begin
  178.         SFPutDesc:= _match ([window o:1],1);    #    Save off the descriptor
  179.         
  180.         LogStr("############## Standard File - Save  ##############");
  181.         if (pNameDoc = "") 
  182.             pNameDoc := GetNewFileName();    #To get a name    
  183.     
  184.         pNameDoc := TruncateString(pNameDoc, 31);
  185.  
  186.         if (pPathlist) and (gIsSys7)      # No navigating in 6.0
  187.             SFNavigate( pPathlist ,1);
  188.         
  189.         if (global gSaveAsHook1)        # app specific hook 
  190.             call (gSaveAsHook1);        # Useful for saving in other formats 
  191.     
  192.         TypeStr(pNameDoc);        # Type the name of the Document
  193.         SpecialKey(ReturnKey, 'Return Key');    # Accept the SF dialog
  194.         
  195.         wait(3);
  196.         if (global gReplaceExisting)
  197.             Call(gReplaceExisting,pReplaceFlag,pNameDoc);
  198.         else
  199.         begin
  200.             ## 7.0 and 6.0 have different 'Replace Existing' dialogs
  201.             ## Determine if Replace Existing Dialog is present
  202.             if(_MatchBoolean([button w:[window o:1]]))
  203.             begin
  204.                 ReplaceExisting := _collect([button w:[window o:1]]);        
  205.                 if (Card(ReplaceExisting) = 2)
  206.                 begin
  207.                     pNameDoc := ReplaceExist(pReplaceFlag, pNameDoc);
  208.                     returnval:= 2;
  209.                 end;
  210.             end;
  211.             else
  212.             begin
  213.                 wait(5);    # If couldn't match Replace Existing Try try again
  214.                 if(_MatchBoolean([button w:[window o:1]]))
  215.                 begin
  216.                     ReplaceExisting := _collect([button w:[window o:1]]);        
  217.                     if (Card(ReplaceExisting) = 2)
  218.                     begin
  219.                         pNameDoc := ReplaceExist(pReplaceFlag, pNameDoc);
  220.                         returnval:= 2;
  221.                     end;
  222.                     else 
  223.                         DialogCheck("",1);    # Look for other problems
  224.                 end;
  225.             end;
  226.         end;
  227.         
  228.         if (global gSaveAsHook2)            # app specific hook 
  229.             Call (gSaveAsHook2);            # This can be useful in performance testing
  230.             
  231.         if not FindWindow(SFPutDesc, true)    # if we can't find SFPut Dialog, indicates saved document for 1st time
  232.         begin    
  233.             if not (returnval)                # if not already reset from replace exist
  234.             begin
  235.                 returnVal := 1;                # set to success - no replace exist done
  236.                 TCSStart({ 2, global kTCSetSFSave },"Save a new file");
  237.                 TCSEnd({ 2, global kTCSetSFSave },1,,,pNameDoc);
  238.             end; # if not returnval
  239.         end;
  240.         
  241.         if (global gSaveAsHook3)                # app specific
  242.             call (gSaveAsHook3);                # hook for handling anything
  243.         
  244.         if (returnval)
  245.         begin
  246.             gLastSavedFile := pNameDoc;
  247.             theFile := '';
  248.             if (pCheckSaveDocWindow)
  249.             begin
  250.                 if (global gCustomRetrievedDoc)
  251.                     theFile := FindWindow(gCustomRetrievedDoc);
  252.                 else
  253.                     theFile := FindWindow(0);
  254.             end;
  255.             gActualFileName := theFile.t;
  256.             if(gActualFileName)
  257.                 str := "The document's window is named - '{gActualFileName}'";
  258.             else
  259.             begin
  260.                 gActualFileName := pNameDoc;
  261.                 str := "The document is named - '{gActualFileName}'";
  262.             end;
  263.             LogStr(str);
  264.         end;
  265.         else
  266.             logstr('Unable to dismiss the SFPut Dialog');
  267.         
  268.     end; # if (IsStandardFile())
  269.     
  270.     return(returnVal);
  271. end; # SaveAs()
  272.  
  273. #########################################################################
  274. #        OpenFile(pNameDoc,pSelectOpen, pPathList, pPartialPath)
  275. #========================================================================
  276. # Author:        KTA
  277. # Description:    This routine will select 'Open' from the 'File' menu, type
  278. #                the string held in the pNameDoc parameter, and
  279. #                then press the returnkey.  It will check to see that
  280. #                the frontmost window's title contains pNameDoc.  If not,
  281. #                it assumes that the wrong file opened.  It will not select
  282. #                'Open' if the pSelectOpen parameter is false.
  283. # Parameters:    pNameDoc - string name of document to open
  284. #                pSelectOpen - 0 to disable selecting of the 'Open' menu item.
  285. #                             1 to select 'Open' from the 'File' menu
  286. #                             2 keyEq - 'o'
  287. #                            list - list containing ordinality of 'Open' menuItem.
  288. #                pPathList - list defining path if file named <pNameDoc> not in
  289. #                        the current directory
  290. #                pPartialPath := Whether to start navigation at the current dir or 
  291. #                                at the desktop
  292. #                            1 - start at current directory
  293. #                            0 - start at desktop (not partial)
  294. # Returns:        1 - Document opened OK
  295. #                0 - Document not opened OK
  296. # Assumptions:    Works with SF_Get, but don't have pNameDoc be to long
  297. #                of a string.
  298. # Examples:        OpenFile('Untit'); will select a document such as 'Untitled'.
  299. #========================================================================
  300. # History:
  301. # RTV    1/7/94        OpenFile was passing a list to TCSEnd instead of a string for the doc name
  302. # KTA    7/06/93        Performance support: OpenFileHook, EndTimer and 
  303. #                    modified gCustomRetrievedDoc check
  304. # KTA    7/07/93        Ability to pass in open menu, if pSelectOpen is list of menuItems
  305. #                     Added global Actualfile so that we can do a better check to see if 
  306. #                    the right file was opened. (intl)
  307. # KTA    7/22/93        added isSubString(pNameDoc,DocName) better filename verification
  308. # KTA    7/29/93        Changed check for StandardFile being Present
  309. # KTA    8/24/93        TCS stack parity check
  310. # KTA    9/9/93        Removed the slang 'BuckWheat' from the output line.
  311. # KTA    9/22/93        Changed gOpenFileHook to gOpenFileHook1
  312. #                     Changed gEndTimer to gOpenFileHook2
  313. #                     Removed gTimedEvent
  314. # ML    4/20/94        Handle Mac Easy Open Dialog
  315. # ML    5/2/94        Better check for MacEasy Open dialog
  316. # ML    5/3/94        Better check for MacEasy Open dialog
  317. # ML     11/29/94    Added exception handling support
  318. # KTA    2/14/95        Added BooleanFlag to FindWindow() call
  319. # MDF    04/29/96    Removed feature for Mac Easy Open Dialog (bug #1333521).
  320. #########################################################################
  321. TASK OpenFile(pNameDoc := "", pSelectOpen := 1, pPathList :={}, pPartialPath := 0) 
  322. begin    
  323.     global gIsSys7, gActualFileName;
  324.     returnVal := 0;
  325.     failStr := "";
  326.  
  327.     if(isUndefined(global gIsSys7))
  328.         isSystem7();
  329.     
  330.     if(pNameDoc)
  331.     begin
  332.         TCSStart({ 1, global kTCSetOpenDoc },"OpenFile");        # Start TCS
  333.     
  334.         if (pSelectOpen) 
  335.         begin
  336.             if (Typeof(pSelectOpen) = 'list') 
  337.                 selectmenuItem(pSelectOpen[1], pSelectOpen[2]);    # Select the Open menuItem for intl
  338.             else if (pSelectOpen = 1) 
  339.                 selectmenuItem("Open", "File");    # Select the Open menuItem
  340.             else if (pSelectOpen = 2) 
  341.                 KeyEq('o');                        # Keyboard equivelant 'o' for open
  342.         end;    
  343.         wait(2);
  344.         SFDialog := IsStandardFile();
  345.         if (SFDialog) 
  346.         begin
  347.             LogStr( "############## Standard File - Open  ##############");
  348.             if ( pPathList ) and (global gIsSys7)    # No navigating in 6.0
  349.                 SFNavigate(pPathList,,,pPartialPath);
  350.             
  351.             if(global gOpenFileHook1)
  352.                 call (gOpenFileHook1);                # Hook to do whatever required prior to typing filename
  353.             
  354.             TypeStr(pNameDoc);                        # Type the name of the file to open
  355.  
  356.             SpecialKey(ReturnKey, 'Return Key');    # Accept the dialog
  357.             
  358.             if(global gOpenFileHook2)
  359.                 Call(gOpenFileHook2);        # Hook can be used for Performance
  360.             Wait(3);
  361.             
  362.             #### Check to make sure Standard file is no longer present
  363.             if (FindWindow(SFDialog, true))         # Call but don't log that it's not there
  364.             begin
  365.                 failStr := "!@#$% Standard File is still present and it shouldn't be";
  366.                 LogStr(failStr);
  367.                 KeyEq('.');                # Exit (changed from 'cancel' button - intl)
  368.             end;
  369.             else if (global gCustomRetrievedDoc)
  370.             begin
  371.                 customDoc := _match (gCustomRetrievedDoc,1);
  372.                 if(customDoc)
  373.                 begin
  374.                     DocName := customDoc.t;
  375.                     LogStr("The front window is named '{DocName}'");
  376.                     returnVal := 1;                        # return success
  377.                 end;
  378.                 else begin
  379.                     failStr := "!@#$% It appears that the wrong file was opened - {DocName}";
  380.                     LogStr(failStr);
  381.                 end;
  382.             end; # else if global gCustomRetrievedDoc
  383.             else # else do default doc checking
  384.             begin
  385.                 ### match the top document window (Hopefully the Document that was just opened)
  386.                 theDoc := findWindow(0);        # Match the document window
  387.                 DocName := theDoc.t;
  388.                 if not(DocName)
  389.                     LogStr("!@#$% No open window with grow and zoom boxes");
  390.                 else
  391.                     LogStr("The front document is named '{DocName}'");
  392.                 
  393.                 ## Is the document the one we expected
  394.                 if (isSubString(DocName,gActualFileName) or isSubString(pNameDoc,DocName))        # looks like the right file
  395.                     returnVal := 1;                        # return success
  396.                 else
  397.                 begin
  398.                     failStr := "!@#$% It appears that the wrong file was opened - {DocName}";
  399.                     LogStr(failStr); 
  400.                 end;
  401.             end; #  else do default doc checking
  402.         end; # if (IsStandardFile())
  403.         TCSEnd({ 1, global kTCSetOpenDoc },returnVal,failStr,, DocName );
  404.     end;
  405.     else
  406.         LogStr("!@#$% No file name was specified");
  407.  
  408.     return(returnVal);
  409. end;  # OpenFile()
  410.  
  411. #########################################################################
  412. #            SFNavigate(pPathList, pTEToggle, pFinalReturn, pPartialPath)    
  413. #========================================================================
  414. # Author:        KTA
  415. # Description:    Controls the navigation in Standard File. 
  416. #                Assigns a global gSFOriginalPath to the current directory 
  417. #                for return navigation.
  418. #                Passes all parameters to SFType which performs actual navigation.
  419. # Parameters:    pPathList := List of directories beginning with the disk name.
  420. #                            if pathlist := {} navigation will go to the Desktop.
  421. #                            otherwise it should be in the form {'hd', 'folder'};
  422. #                pTEToggle := Whether toggling from a text edit field is required 
  423. #                            to navigate.
  424. #                            1 - Toggle
  425. #                            0 - No toggling required
  426. #                pPartialPath := Whether to start navigation at the current dir or 
  427. #                                at the desktop
  428. #                            1 - start at current directory
  429. #                            0 - start at desktop
  430. #                pFinalReturn := Whether to accept the final item in <pPathList>
  431. # Returns:        PathList
  432. #                Also sets global gSFOriginalPath to the original path
  433. #========================================================================
  434. # History:
  435. # KTA    7/18/94    Added a check to insure that PathList is defined.
  436. # ML 11/29/94    Added exception handling support
  437. # KTA 1/9/95    Fixed bug when StandardFile was already at the Desktop errors occured
  438. #########################################################################
  439. TASK SFNavigate( pPathList :={},pTEToggle :=0, pFinalReturn := 1, pPartialPath := 0) 
  440. begin
  441.     # Verify that Standard File is present
  442.     if (IsStandardFile()) 
  443.     begin
  444.         NavigationRequired := 1;
  445.         OrigPathList :={};                        # Initialize variable    
  446.         try
  447.             match[popup i:?Popupitems];                # match SF popup 
  448.         catch theError
  449.             ExceptionDispatcher(theError);
  450.         for x := 1 to (card PopUpItems-1)        # Build a Pathlist 
  451.             OrigPathList := insert(PopUpItems[x].t,1,OrigPathList);
  452.  
  453.         if (OrigPathList = pPathList)            # Is the current directory the desired directory
  454.         begin
  455.             NavigationRequired := 0;
  456.             LogStr("The current directory is the desired directory - no navigation required");
  457.         end;
  458.         else if (TypeOf(pPathList) = "integer")     # return to where you started
  459.         begin
  460.             if (pPathList = 1)     
  461.                 pPathList := Global gSFOriginalPath;
  462.         end;
  463.             
  464.         gSFOriginalPath := OrigPathList;
  465.         
  466.         if(NavigationRequired)
  467.         begin
  468.             SFPath := '';
  469.             if(pPathList)
  470.             begin
  471.                 for each item in pPathList                 # For logging purposes - build pathlist
  472.                     SFPath := SFPath + Item + ":";
  473.             end;
  474.             else
  475.                 SFPath := 'DeskTop:';
  476.             LogStr( "Standard File Navigation to the path - ∂[{SFPath}∂]",3);
  477.             
  478.             SFType(pPathList,pTEToggle, pFinalReturn, pPartialPath);
  479.         end;
  480.         Return(pPathList);
  481.     end;
  482.     else
  483.         return(0);
  484. end; # SFNavigate()
  485.  
  486.  
  487. #########################################################################
  488. #            SFType(pPathList, pTEToggle, pFinalReturn, pPartialPath)    
  489. #========================================================================
  490. # Author:        KTA
  491. # Description:    Performs navigation in Standard File.
  492. #                If <pPartialPath> evaluates to false, Selects the 'DeskTop' button.
  493. #                Then types each item in <pPathList> followed by a returnKey.
  494. # Parameters:    pPathList := List of directories beginning with the disk name.
  495. #                pTEToggle := Whether toggling from a text edit field is required 
  496. #                            to navigate.
  497. #                            1 - Toggle
  498. #                            0 - No toggling required
  499. #                pPartialPath := Whether to start navigation at the current dir or 
  500. #                                at the desktop
  501. #                            1 - start at current dir
  502. #                            0 - start at desktop
  503. #                pFinalReturn := Whether to accept the final item in <pPathList>
  504. # Returns:        Nada
  505. #========================================================================
  506. # History:
  507. # ML     11/29/94    Added exception handling support
  508. # KTA 1/9/95    Fixed bug when StandardFile was already at the Desktop errors occured
  509. #########################################################################
  510. TASK SFType(pPathList,pTEToggle :=0, pFinalReturn := 1, pPartialPath := 0)
  511. begin
  512.     if not (pPartialPath)
  513.     begin
  514.         if(_MatchBoolean([button t:'Desktop' e:True]))
  515.             SelectButton('Desktop');
  516.     end;
  517.     if(pPathList)
  518.     begin
  519.         if (pTEToggle)
  520.             _type ({TabKey});        # Makes directory list active
  521.         wait(2);
  522.         TypeList(pPathList,1,pFinalReturn);    # Actual navigation
  523.         if (pTEToggle)
  524.             _type ({TabKey});        # Makes text edit  active
  525.     end;
  526. end; # SFType()
  527.  
  528. #########################################################################
  529. #            ReplaceExist( pReplaceFlag,pNameDoc)    
  530. #========================================================================
  531. # Author:        KTA
  532. # Description:    Handles the 'Replace existing?' dialog.
  533. # Parameters:    pReplaceFlag - Whether to Replace a document with the same name
  534. #                        or generate a unique name.
  535. #                        1 - Overwrite document with same name.
  536. #                        0 - Do not overwrite.  Generate unique name.
  537. #                pNameDoc := Name of file which already exists on disk.
  538. # Returns:        pNameDoc ( will be identical to the initial one if pReplaceFlag is set)
  539. #========================================================================
  540. # History:
  541. # KTA    8/24/93        TCS stack parity check
  542. #    ML    4/07/94        Added gReplaceExistHook1, gReplaceExistHook2
  543. #                    modal dialog blocks external tool calls
  544. # ML     11/29/94    Added exception handling support
  545. # KTA    2/28/95        Handle filenames longer than 31 characters
  546. # KTA    2/28/95        Added call to TruncateString().
  547. #########################################################################
  548. TASK ReplaceExist( pReplaceFlag := true, pNameDoc :='') 
  549. begin
  550.     global gIsSys7, gReplaceExistHook1, gReplaceExistHook2;
  551.     LogStr("    -- Replace Existing?? --");
  552.     
  553.     if (gReplaceExistHook1)
  554.         call (gReplaceExistHook1);
  555.         
  556.     # Different button names on dialog
  557.      myButton := _collect([button w:[window o:1]]);
  558.     firstButton := MyButton[1];
  559.     secondButton := MyButton[2];
  560.     if (firstButton.r[1] < secondButton.r[1])
  561.     begin
  562.         CancelString := firstButton.t;
  563.         ReplaceString := secondButton.t;
  564.     end;
  565.     else
  566.     begin
  567.         ReplaceString := firstButton.t;
  568.         CancelString := secondButton.t;
  569.     end;
  570.  
  571.     if (pReplaceFlag)        # Want to replace
  572.     begin
  573.         TCSStart({ 4, global kTCSetSFSave },"ReplaceExisting");        # Start TCS
  574.         if(SelectButton(ReplaceString))
  575.             returnVal := 1;
  576.         else
  577.             returnVal := 0;
  578.         TCSEnd({ 4, global kTCSetSFSave }, returnVal);
  579.     end;
  580.     else 
  581.     begin                    # Don't want to replace
  582.         TCSStart({ 3, global kTCSetSFSave },"CancelNewName");        # Start TCS
  583.         if(SelectButton(CancelString))
  584.             returnVal := 1;
  585.         else
  586.             returnVal := 0;
  587.             
  588.         TimeString := GetNewFileName(pNameDoc);
  589.         if(global gIsSys7)        # 7.0 and 6.0 handle text entry differently in SF
  590.             _type ({rightArrowKey});        # Places I beam after existing text in SF text edit
  591.             
  592.         numChars := Card(pNameDoc);
  593.         if (numChars >= 25)        # Make sure we can add 7 char timestamp to make the file unique
  594.         begin
  595.             numAdditional := card(TimeString);
  596.             numTimes := numAdditional - (31 - numChars);
  597.             SpecialKey(deleteKey, 'DeleteKey', numTimes);
  598.             tempStr := '';
  599.                 
  600.             pNameDoc := TruncateString(pNameDoc, 31 - numAdditional);
  601.         end;
  602.         pNameDoc := "{pNameDoc}{TimeString}";
  603.         
  604.         TypeStr("{TimeString}");        # append time to pNameDoc in 6.0/7.0
  605.         SpecialKey(returnKey, 'Return key');
  606.         TCSEnd({ 3, global kTCSetSFSave },returnVal,,pNameDoc);
  607.     end;
  608.  
  609.     if (gReplaceExistHook2)
  610.         call (gReplaceExistHook2);
  611.  
  612.     return(pNameDoc);
  613. end; # ReplaceExist()
  614.  
  615. #########################################################################
  616. #                            GetNewFileName(pFileName, pIncludeNameFlag)    
  617. #========================================================================
  618. # Author:        SL
  619. # Description:    Gets a new file name by concatenating the app name and
  620. #                the current time.
  621. # Parameters:    pFileName -    If this parameter is present, this routine will
  622. #                        only pass back the time.  If this parameter is not
  623. #                        present, then this routine will pass back a string
  624. #                        consisting of the application name with the time
  625. #                        appended to it.
  626. #                pIncludeNameFlag - if true will append time and Sec to end of 
  627. #                            name and return it.
  628. # Returns:        newFileName - string name for new file name
  629. #                    or just a time and Sec string
  630. #========================================================================
  631. # History:
  632. # ML     11/29/94    Added exception handling support
  633. # ML    12/13/94    Removed global IsSys7
  634. #########################################################################
  635. TASK GetNewFileName(pFileName :="",pIncludeNameFlag := 0)
  636. begin
  637.     match [time h:?Tm s:?Sc];
  638.     if (pFileName)
  639.     begin 
  640.         if(pIncludeNameFlag)
  641.             newFileName := "{pFileName} {Tm}{Sc}"; 
  642.         else 
  643.             newFileName := " {Tm}{Sc}"; 
  644.     end;
  645.     else 
  646.     begin
  647.         try match [Application t:?appName];
  648.         catch theError
  649.             ExceptionDispatcher(theError);
  650.         newFileName := "@!@{appName}-{Tm}{Sc}";
  651.     end;
  652.     return(newFileName);
  653. end; # GetNewFileName()
  654.  
  655. #########################################################################
  656. #             SFSelectPopupMenuItem(pPopupMenuItem) 
  657. #========================================================================
  658. # Author:        KTA
  659. # Description:    Selects the popup menu item <pPopupMenuItem> from the Standard
  660. #                File dialog.
  661. # Parameters:    pPopupMenuItem -    The ordinality or Title of the menuitem (where
  662. #                                the Displayed menuItem is ord 1 if using Ordinality).
  663. # Returns:        nothing
  664. # Examples:        SelectPopupMenuItem("Font");
  665. #                SelectPopupMenuItem(2);
  666. # Assumptions:    The popup menu is in window ord 1
  667. #========================================================================
  668. # History:
  669. # ML     11/29/94    Added exception handling support
  670. #########################################################################
  671. TASK SFSelectPopupMenuItem( pPopupMenuItem := '')
  672. begin
  673.     if (IsStandardFile()) 
  674.     begin
  675.         try PopupMenu := match[popup R:?ThePopUpRect i:?PopupMenuItems];
  676.         catch theError
  677.             ExceptionDispatcher(theError);
  678.         if (pPopupMenuItem = 0)
  679.             return(1);
  680.         x := ((ThePopUpRect[1]+ThePopUpRect[3])/2);
  681.         y := ((ThePopUpRect[2]+ThePopUpRect[4])/2);
  682.         
  683.         if not(TypeOf(pPopupMenuItem) = 'integer') 
  684.         begin
  685.             try Match[MenuItem t:/{pPopupMenuItem}≈/ o:?PopUpOrd m:[Popup]];
  686.             catch theError
  687.                 ExceptionDispatcher(theError);
  688.             pPopupMenuItem := PopUpOrd;
  689.         end;
  690.     
  691.         ### do our own logging
  692.         temp := global gDisableAllLogging;
  693.         global gDisableAllLogging := 1;
  694.         ### Now select menuitem
  695.         MoveMouse(x,y);
  696.         _pressMouse();
  697.         wait(1);
  698.         _move ('r',{ 0,16 * (pPopupMenuItem - 1) });
  699.         wait(1);
  700.         _releaseMouse();
  701.     
  702.         ### restore logging
  703.         global gDisableAllLogging := temp;
  704.         thePopupName := PopupMenuItems[pPopupMenuItem].t;
  705.     
  706.         ### log what just happened
  707.         LogStr("Selected popup menu item ∂'{thePopupName}∂' from the Standard File popUp");
  708.         Return(thePopupName);
  709.     end;
  710.     else 
  711.         return(0);
  712. end;
  713.  
  714. #########################################################################
  715. #                        ModifyDocument()
  716. #========================================================================
  717. # Author:        KTA
  718. # Description:    This task is called to modify a document so a revert to saved can
  719. #                be performed.  If a global tqask reference (gModifyDocument) is 
  720. #                defined, it will be called. Otherwise the default of typing a
  721. #                string will be used.
  722. # Parameters:    none
  723. # Returns:        0 - failure
  724. #                1 - success
  725. # Examples:        ModifyDocument()
  726. # Assumptions:    
  727. #========================================================================
  728. # History:
  729. # KTA    7/30/93     Added returnVal and return
  730. # KTA    9/28/93     isUndefined(returnVal)
  731. # KTA    9/28/93     Added TCS - 'Modify a Document'
  732. # KTA    10/05/93 Change returnVal to a 1 if it was successful
  733. # KTA    12/14/93 gModifyDoc can return a -1 and test was unsuccessful
  734. #########################################################################
  735. TASK ModifyDocument()
  736. begin
  737.     TCReturnVal := 0;
  738.     ErrStr := "";
  739.     TCSStart({ 1, global kTCSetRevertDoc }, "Modify a Document");
  740.     if (global gModifyDocument)
  741.     begin
  742.         TCReturnVal := call (gModifyDocument);
  743.         if(isUndefined(TCReturnVal))        # If the gModifyDocument hook doesn't return a value
  744.         begin
  745.             ErrStr := "Failed because there was no return value";
  746.             TCReturnVal := 0;        # no value returned from hook - have to fail.
  747.         end;
  748.         
  749.         if(TCReturnVal < 1)        # if gModifyDoc was successFul
  750.             returnVal := 0;        # return a failure
  751.         else
  752.             returnVal := 1;        # return a success
  753.     end;
  754.     else
  755.     begin
  756.         TypeStr("If 'Revert' worked, this shouldn't be here!");
  757.         TCReturnVal := 1;        #Hopefully this works to modify the document
  758.         returnVal := 1;        # return a success
  759.     end;
  760.     TCSEnd({ 1, global kTCSetRevertDoc }, TCReturnVal, ErrStr);
  761.     return(returnVal);
  762. end;
  763.  
  764. #########################################################################
  765. #                        Revert(pRevertMI)
  766. #========================================================================
  767. # Author:        KTA
  768. # Description:    If RevertMI is defined as the menuItem for revert it will be selected.
  769. #                Otherwise a menuItem with the word 'Revert' in it will be selected. 
  770. #                A dialog will normally appear confirming the revert request.  
  771. #                Several methods will be used when attempting to dismiss the dialog.
  772. #                Attempts to matck buttons "OK", "Yes", "Revert", are made, then 
  773. #                typing the returnKey.  If RevertMi is defined then DialogCheck()
  774. #                Will be called to output the static text in the dialog and the type
  775. #                the returnKey.
  776. # Parameters:    pRevertMI - List containing the ordinality of the revert menuItem. 
  777. # Returns:        nada
  778. # Examples:        Revert()
  779. # Assumptions:    
  780. #========================================================================
  781. # History:
  782. # KTA    7/12/93        Pass in pRevertMI for intl
  783. # KTA    8/24/93        TCS stack parity check
  784. # KTA    10/15/93    Added longer wait before trying to dismiss dialog and 
  785. #                    support for hierachical menus
  786. # ML     11/29/94    Added exception handling support
  787. # ML    11/29/94    Revise for correct logging if not "Revert" menuitem
  788. #                     Added return value
  789. # ML    11/20/95    add support for gRevertString, gOKString, gYesString (int'l)
  790. # MDF    04/26/96    Fixed bug in Intl case where revert button wouldn't get
  791. #                    selected if it wasn't the default.
  792. #########################################################################
  793. TASK Revert(pRevertMI := '')
  794. begin
  795.     global gApptitle, gRevertString, gOKString, gYesString;
  796.     returnVal := 0;
  797.     failStr := '';
  798.  
  799.     if (IsUndefined (gRevertString))
  800.         revertString := "Revert";
  801.     else
  802.         revertString := gRevertString;
  803.     if (IsUndefined (gOKString))
  804.         okString := "OK";
  805.     else
  806.         okString := gOKString;
  807.     if (IsUndefined (gYesString))
  808.         yesString := "Yes";
  809.     else
  810.         yesString := gYesString;
  811.  
  812.     TCSStart({ 2, global kTCSetRevertDoc },"Revert");        # Start TCS
  813.     if (pRevertMI = '')
  814.     begin
  815.         if (_matchBoolean (
  816.         [menu t:'File' i:{ [menuItem t:/Revert≈(≈∂n≈)*/ e:true o:?ord] } ]))
  817.         begin
  818.             try begin
  819.                 match [menu t:'File' i:{ [menuItem t:/Revert≈(≈∂n≈)*/ e:true o:?ord] } ]!;
  820.                 match [menu t:'File' i:{ [menuItem t:?item e:true o:ord] } ]!;
  821.                 SelectMenuItem(item,'File');
  822.                 if (_matchBoolean ([button t:okString]))
  823.                     SelectButton('OK');
  824.                 else if (_matchBoolean ([button t:yesString]))
  825.                     SelectButton('Yes');
  826.                 else if (_matchBoolean ([button t:revertString]))
  827.                     SelectButton('Revert');
  828.                 else        # try default if no 'yes' or 'OK' button
  829.                     SpecialKey(returnKey, 'Return key');
  830.                 DialogReturn := DialogCheck("",1);
  831.                 if(DialogReturn)
  832.                     failStr := DialogReturn;
  833.                 else
  834.                     returnVal := 1;
  835.             end; # try
  836.             catch theError
  837.                 ExceptionDispatcher(theError);
  838.         end; # if _matchBoolean
  839.         else
  840.             failStr := "There is no enabled menu item titled 'Revert' in {gApptitle}";
  841.     end; # if (pRevertMI = '')
  842.     Else if(TypeOf(pRevertMI) = 'list')    # Pass in Ord for (Intl)
  843.     begin
  844.         if (Card(pRevertMI) = 2)
  845.             returnVal := SelectMenuItem(pRevertMI[1], pRevertMI[2]);
  846.         else if (Card(pRevertMI) = 3)
  847.             returnVal := SelectMenuItem(pRevertMI[1], pRevertMI[2], pRevertMI[3]);
  848.         Wait(2);
  849.         if (_matchBoolean ([button t:okString]))
  850.             SelectButton(okString);
  851.         else if (_matchBoolean ([button t:yesString]))
  852.             SelectButton(yesString);
  853.         else if (_matchBoolean ([button t:revertString]))
  854.             SelectButton(revertString);
  855.         else        # try default button
  856.             SpecialKey(returnKey, 'Return key');
  857.         DialogCheck("",1);
  858.     end;
  859.     if failStr
  860.         logstr(failStr);
  861.     TCSEnd( { 2, global kTCSetRevertDoc }, returnVal, failStr);
  862.     return(returnVal);
  863. end;
  864.  
  865. #########################################################################
  866. #                        IsStandardFile(pLogIt)
  867. #========================================================================
  868. # Author:        KTA
  869. # Description:    Checks to see if the Standard File dialog is present
  870. # Parameters:    pLogIt - Flag indicating whether or not to output
  871. #                        the nonexistence of the StandardFile dialog.
  872. # Returns:        1 - if the Standard File dialog is present
  873. #                0 - if the Standard File dialog is not present
  874. # Examples:        IsStandardFile()
  875. # Assumptions:    
  876. #========================================================================
  877. # History:
  878. # KTA    7/7/93    Added enhanced check for StandardFile for intl systems
  879. # KTA    7/29/93    If StandardFile return a window descriptor of front window
  880. # ML     11/29/94    Added exception handling support
  881. # ML    2/6/95        Use MatchBoolean instead of Match
  882. #                    Check before collecting button and useritem
  883. # KTA    2/28/95        Insure descriptors are for the front window
  884. #########################################################################
  885. TASK IsStandardFile(pLogIt := 1)
  886. begin
  887.     returnVal := 0;
  888.     if (_matchBoolean([button t:"Desktop" w:[window o:1]]!))
  889.         returnVal := _match([window o:1]!,1);
  890.     else
  891.     begin
  892.         if (_matchBoolean([button w:[window o:1]]))
  893.             NumButtons :=  _collect([button w:[window o:1]]);
  894.         if (_matchBoolean([useritem w:[window o:1]]))
  895.             NumUserItem :=  _collect([useritem w:[window o:1]]);
  896.         if((Card(NumButtons) >= 4) and (Card(NumUserItem) >= 1))
  897.         returnVal := _match([window o:1]!,1);
  898.     end;
  899.     if not(returnVal) and (pLogIt)
  900.         LogStr( "The Standard_File dialog is not present");
  901.  
  902.     return(returnVal);
  903. end;
  904.  
  905. #########################################################################
  906. #                        CancelStandardFile(pHowCancel, pSaveAsMenu)
  907. #========================================================================
  908. # Author:        KTA
  909. # Description:    Selects Save As and Cancels it
  910. # Parameters:    pHowCancel - method to cancel
  911. #                    0 := KeyEq('.');
  912. #                    1 := selectButton('Cancel');
  913. #                    2 := SpecialKey(escapeKey,"Escape key");
  914. #                pSaveAsMenu     -  list containing the ordinality of 'Save As' menu item.
  915. #                            - anything else will cause the hardcoded string 'Save As'
  916. #                                to be use in matching the menuItem.
  917. # Returns:        1 - if cancelling occured as expected
  918. #                0 - if it didn't
  919. # Examples:        CancelStandardFile()
  920. # Assumptions:    
  921. #========================================================================
  922. # History:
  923. # KTA    7/8/93    Added pHowCancel method 2 := escapekey
  924. # KTA    7/8/93    Added pSaveAsMenu the SaveAs menu descriptor
  925. # KTA    8/24/93    TCS stack parity check
  926. # ML     11/29/94    Added exception handling support
  927. # ML    2/6/95        Use MatchBoolean instead of Match
  928. #########################################################################
  929. TASK CancelStandardFile(pHowCancel := 0, pSaveAsMenu := 0)
  930. begin
  931.     failStr := "";
  932.     returnVal := 0;
  933.     
  934.     if(pHowCancel = 1)
  935.         TCSNum := 5;    
  936.     else
  937.         TCSNum := 6;    
  938.         
  939.     TCSStart({ TCSNum, global kTCSetSFSave },"SaveAs/Cancel");        # Start TCS
  940.     if (TypeOf(pSaveAsMenu) = 'list')
  941.         SelectMenuItem(pSaveAsMenu[1],pSaveAsMenu[2]);        ## Save/Cancel
  942.     else
  943.         SelectMenuItem("Save As",'File');        ## Save/Cancel
  944.     wait(3);
  945.     if(IsStandardFile())                    # Check to see if standard file is present
  946.     begin
  947.         if(pHowCancel = 0)
  948.             KeyEq('.');
  949.         else if(pHowCancel = 1)
  950.         begin
  951.             if (_matchBoolean([button t:'Cancel']))
  952.                 selectButton('Cancel');                # Cancel the Standard SF_Put Dialog
  953.             else 
  954.             begin
  955.                 SpecialKey(escapeKey,"Escape key");    # Help insure success - (intl)
  956.                 failStr := "No 'Cancel' button found - Hit the escape key instead.";
  957.             end;
  958.         end;
  959.         else if(pHowCancel = 2)
  960.             SpecialKey(escapeKey,"Escape key");
  961.  
  962.         if not(IsStandardFile(0))                    # Check to see if standard file is not present
  963.             returnVal := 1;
  964.         else
  965.             failStr := "Standard_File is still present and shouldn't be";
  966.     end;
  967.     TCSEnd({ TCSNum, global kTCSetSFSave }, returnVal,failStr);    
  968.     return(returnVal);
  969. end;
  970.  
  971. #########################################################################
  972. #                        Save(pSaveMethod)
  973. #========================================================================
  974. # Author:        KTA
  975. # Description:    Selects Save - calls Save As if Standard File appears
  976. # Parameters:    pSaveMethod - Method to save
  977. #                    1 := Save from File Menu
  978. #                    2 := Command-'s'
  979. # Returns:        Nothing
  980. # Examples:        Save()
  981. # Assumptions:    
  982. #========================================================================
  983. # History:
  984. # KTA    7/8/93    Added pSaveMethod input parameter & pSaveMethod(2)
  985. # KTA    8/24/93    TCS stack parity check
  986. # ML 11/29/94    Added exception handling support
  987. #########################################################################
  988. TASK Save(pSaveMethod := 1)
  989. begin
  990.     if(pSaveMethod = 1)
  991.     begin
  992.         if (_matchBoolean ([menuItem t:'Save' m:[menu t:'File' e:true] e:true]!))
  993.         begin
  994.             TCSStart({ 7, global kTCSetSFSave },"Save using Save menu item");        # Start TCS
  995.             TCSEnd({ 7, global kTCSetSFSave }, SelectMenuItem("Save",'File'));    
  996.             if(isStandardFile(0))    # if StandardFile is present
  997.             begin
  998.                 SaveAs();            # Call SF handler
  999.             end;
  1000.         end;
  1001.         else
  1002.             pSaveMethod := 2;    # Help insure success (intl)
  1003.     end;
  1004.     if(pSaveMethod = 2)
  1005.         keyEq('s');
  1006. end;